<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .btn { 
            width:150px;
            border:1px solid #333;
            text-align: center;
            line-height: 2.5em;
            border-radius: 8px;
            cursor: pointer;
        }
        p {
            width:150px;
            text-align: center;
        }
        .code {
            display: none;
        }
        .show { 
            display:block
        }
    </style>
</head>
<body>
    <div id='btn' class="btn" onclick="setTime(this)">免费获取验证码</div>
    <!-- <div class='code'>
        //获取验证码   
        var count = 60;
        function setTime(val){
            if(count == 0){
                val.removeAttribute("disabled");
                val.innerHTML = "免费获取验证码";
                val.style = 'color:#333;border:1px solid #333;'
            }else {
                val.setAttribute("disabled", "true");
                val.innerHTML = "重新发送("+count+")"
                val.style = 'color: #ccc;border:1px solid #ccc;'
                count --
            }
            setTimeout(function(){
                setTime(val)
            },1000)
        }
    </div> -->
    <!-- <p onclick="showCode(this)">显示代码</p> -->
</body>
<script>
    //获取验证码   
    var count = 60;
    function setTime(val){
        if(count == 0){
            val.removeAttribute("disabled");
            val.innerHTML = "免费获取验证码";
            val.style = 'color:#333;border:1px solid #333;'
        }else {
            val.setAttribute("disabled", "true");
            val.innerHTML = "重新发送("+count+")"
            val.style = 'color: #ccc;border:1px solid #ccc;'
            count --
        }
        setTimeout(function(){
            setTime(val)
        },1000)
    }
    //显示代码
    // function showCode(val){
    //     console.log(val.style.display)
    //     val.className = 'show'
    // }
</script>
</html>